package com.timesheet.gui.efforttracker.actions;

import java.util.List;

import org.eclipse.jface.action.Action;

import com.timesheet.gui.efforttracker.Activator;
import com.timesheet.gui.efforttracker.controllers.SectionEffortCompositeController;
import com.timesheet.server.common.models.EffortTrackerDTO;
import com.timesheet.server.common.models.view.EffortTrackerViewModel;
import com.timesheet.server.common.models.view.EffortTrackerViewModelContainer;
import com.timesheet.server.core.mapper.Mapper3;
import com.timesheet.serverice.EffortTrackerService;

public class DeleteEffortAction extends Action {

	private SectionEffortCompositeController sectionEffortCompositeController;
	
	
	EffortTrackerViewModelContainer modelContainer = EffortTrackerViewModelContainer.getInstance();

	public DeleteEffortAction(SectionEffortCompositeController sectionEffortCompositeController) {

		this.sectionEffortCompositeController = sectionEffortCompositeController;
		setId("DeleteEffortAction");
		setImageDescriptor(Activator.getImageDescriptor("icons/delete_edit.gif"));

	}

	@Override
	public void run() {		
		System.out.println("Inside the DeleteEffortAction");		
		EffortTrackerViewModel effortTrackerViewModel = modelContainer.getEffortTrackerViewModel();
		
		EffortTrackerService effortTrackerService = new EffortTrackerService();		
		try {
			EffortTrackerDTO map = Mapper3.map(new EffortTrackerDTO(), effortTrackerViewModel);
			if(effortTrackerService.deleteEffort(map)){
				List<EffortTrackerViewModel> list = modelContainer.getList();
				
				list.remove(effortTrackerViewModel);
				
				modelContainer.setList(list);modelContainer.refresh();
				
				//modelContainer.notify(true);
				//modelContainer.setEffortTrackerViewModel(effortTrackerViewModel);
				
			}
		} catch (Exception e) {			
			e.printStackTrace();
		}
		
		
		
		
	}

}
